package lambda;

import org.junit.Test;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by Administrator on 2020/2/18.
 */
public class FunctionInterfaceTest {
    @Test
    public void testlambda(){
        fun(new FunctionInterface() {
            @Override
            public boolean test(int param) {
                System.out.println("一般代码实现" + param);
                if (param > 50) {
                    return false;
                } else {
                    return true;
                }
            }
        });
        fun((int param)-> {
            System.out.println("lambda代码方式实现"+param);
            if(param >50){
                return false;
            }else{
                return true;
            }
        });
    }
    @Test
    public void streamTest(){
        List<String> list = Stream.of("one", "two", "three", "four").filter(k -> k.length()>3).peek(k -> System.out.println("过滤后元素"+k))
                .map(k -> k.toUpperCase()).peek(k -> System.out.println("map后元素"+k)).collect(Collectors.toList());
        for (String s :list){
            System.out.println(s);
        }
    }
    private void fun(FunctionInterface functionInterface){
        int param = 99;
        boolean flag = functionInterface.test(param);
        System.out.println(flag);
    }
}
